module.exports = (app) => {
    const { STRING, INTEGER, DATE, ENUM, TEXT } = app.Sequelize;

    const Score = app.model.define("score", {
        id: {
            type: INTEGER(20),
            primaryKey: true,
            autoIncrement: true,
        },
        user_id: {
            type: INTEGER,
            allowNull: false,
            defaultValue: 0,
            comment: "用户id"
        },
        exam_id: {
            type: INTEGER,
            allowNull: false,
            defaultValue: 0,
            comment: "成绩单id"
        },
        class_id: {
            type: INTEGER,
            allowNull: false,
            defaultValue: 0,
            comment: "班级id"
        },
        branch_id: {
            type: INTEGER,
            allowNull: false,
            defaultValue: 0,
            comment: "学科id"
        },
        score: {
            type: INTEGER,
            allowNull: false,
            defaultValue: 0,
            comment: "分数",
        },
        image: {
            type: STRING,
            allowNull: true,
            defaultValue: "",
            comment: "附件",
        },
        comment: {
            type: STRING,
            allowNull: true,
            defaultValue: "",
            comment: "点评",
        },
        status: {
            type: INTEGER(1),
            allowNull: false,
            defaultValue: 0,
            comment: "状态 0取消 1正常",
        },
        created_time: {
            type: DATE,
            get() {
                return app.formatTime(this.getDataValue('created_time'))
            }
        },
        updated_time: DATE,
    });

    // 关联关系
    Score.associate = function() {
        app.model.Score.belongsTo(app.model.User, { foreignKey: 'user_id' });
        app.model.Score.belongsTo(app.model.Class, { foreignKey: 'class_id' });
        app.model.Score.belongsTo(app.model.Branch, { foreignKey: 'branch_id' });
        app.model.Score.belongsTo(app.model.Exam, { foreignKey: 'exam_id' });
      };

    return Score;
};